{extend name="index/iframe" /}

{block name="content"}
<form class="layui-form layui-form-my" action="">
    <input type="hidden" value="{$Think.get.id}" name="id">
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">公告类型</label>
        <div class="layui-input-block">
            <select name="type" id="type" lay-filter="type"  lay-verify="required">
                <option value="">全部</option>
                {foreach $notice_type as $k=>$v}
                    <option value="{$k}"  {$v==$find['type'] ? 'selected' : ''}>{$v}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">公告标题</label>
        <div class="layui-input-block">
            <input type="text" name="title" value="{$find.title}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">发布人</label>
        <div class="layui-input-block">
            <input type="text" name="writer" value="{$find.writer}" lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">发布日期</label>
        <div class="layui-input-block">
            <input type="text" name="start_time" value="{$find.start_time}" id="datetime" lay-verify="datetime" placeholder="yyyy-MM-dd HH:mm:ss" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">内容</label>
        <div class="layui-input-block" style="width: 700px;">
            <textarea id="content" name="content" style="display: none;">{$find.content}</textarea>
        </div>
    </div>
    <div class="layui-form-item" style="margin-bottom: 100px;">
        <div class="layui-input-block">
            <button class="layui-btn my-btn" lay-submit="" lay-filter="submitBtn">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
{/block}

{block name="css"}{/block}

{block name="js"}
<script>
    layui.use(['form', 'layedit', 'laydate', 'upload', 'element'], function(){
        var form = layui.form
            ,$ = layui.$
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,layedit = layui.layedit;

        //html编辑器
        layedit.set({
            uploadImage: {
                url: '{:url("Base/upload", "name=notice")}'
            }
        });
        var index = layedit.build('content', {height: 600});

        //日期
        laydate.render({
            elem: '#datetime'
            ,type: 'datetime'
        });

        //提交
        form.on('submit(submitBtn)', function(data){
            data.field.content = layedit.getContent(index);
            var load = layer.load();
            $.post('{:url("Notice/edit")}',data.field, function(json){
                layer.close(load);
                json.code==0 ? layer.msg(json.msg, {icon: 1, time: 1000}) : layer.msg(json.msg, {icon: 0, time: 1000});
                window.location.reload();
            }, 'JSON').error(function(){
                layer.close(load);
                layer.msg('连接超时，请联系后台管理员', {icon: 2, time:3000});
            });
            return false;
        });
    });
</script>
{/block}